(function(){
	// Id of links container
	this.containerId="webinar";
	// Query string and partnerref vars
	this.qs=null;
	this.partnerRef=null;
	// Init function adds getQueryString callback to onload event
	this.init=function(){
		var func=function(){this.getQueryString()};
		var oldonload=window.onload;
		if(typeof(window.onload)!="function"){
			window.onload=func;
		}
		else {
			window.onload=function(){
				oldonload();
				func();
			}
		}
	};
	// Get and prepare querystring
	this.getQueryString=function(){
		var qs=location.search.substring(1,location.search.length);
		if(qs.length===0){
			// If there is no qs then still prepare links
			// incase we need to remove dummy partnerrefs
			this.prepareLinks();
			return;
		}
		this.qs=qs.replace(/\+/g," ");
		this.getPartnerRef();
	};
	// Get partnerref from query string
	this.getPartnerRef=function(){
		var params=this.qs.split(/&(?:amp;)?/);
		for(var i=0; i<params.length; i++){
			if(params[i].match(/^partnerref=/)){
				this.partnerRef=params[i].split("=")[1];
				break;
			}
		}
		// Again, always prepare links even if
		// partnerref is not found in qs
		this.prepareLinks();
	};
	// Prepare links within link container
	this.prepareLinks=function(){
		var linkContainer=document.getElementById(this.containerId);
		if(!linkContainer) return;
		var links=linkContainer.getElementsByTagName("a");
		for(var i=0; i<links.length; i++){
			var linkUrl=links[i].href;
			// Start by removing dummy partnerrefs
			links[i].href=linkUrl.replace(/partnerref=/,"_removedpartnerref=");
			// If actual partnerref is saved then add it
			if(this.partnerRef)
				links[i].href=links[i].href+(linkUrl.match(/.+\?/)? "&":"?")+"partnerref="+this.partnerRef;
		}
	};
	// Start the whole thing off
	this.init();
})();